﻿using System;
using System.Web.UI;

namespace ECommerce.Controls
{
	public partial class OrderProgress : BaseUserControl
	{
		protected void Page_Load(object sender, EventArgs e)
		{
		}

		protected void Page_PreRender(object sender, EventArgs e)
		{
			SetStatus();
			SetLinks();

			hlCart.Text = GetLocalResourceString("OrderProgress.CartStep");
			hlOrdering.Text = GetLocalResourceString("OrderProgress.OrderingStep");
			hlComplete.Text = GetLocalResourceString("OrderProgress.CompleteStep");
			hlConfirm.Text = GetLocalResourceString("OrderProgress.ConfirmStep");
		}

		private void SetStatus()
		{
			hlCart.CssClass = GetStatusCss("Cart");
			hlOrdering.CssClass = GetStatusCss("Ordering");
			hlConfirm.CssClass = GetStatusCss("Confirm");
			hlComplete.CssClass = GetStatusCss("Complete");
		}

		private void SetLinks()
		{
			switch(this.OrderProgressStep.ToLowerInvariant())
			{
				case "cart":
					{
						hlCart.NavigateUrl = CommonHelper.GetStoreLocation() + "shoppingcart.aspx";
						hlOrdering.NavigateUrl = string.Empty;
						hlConfirm.NavigateUrl = string.Empty;
						hlComplete.NavigateUrl = string.Empty;
					}
					break;
				case "ordering":
					{
						hlCart.NavigateUrl = CommonHelper.GetStoreLocation() + "shoppingcart.aspx";
						hlOrdering.NavigateUrl = CommonHelper.GetStoreLocation() + "ordering.aspx";
						hlConfirm.NavigateUrl = string.Empty;
						hlComplete.NavigateUrl = string.Empty;
					}
					break;
				case "confirm":
					{
						hlCart.NavigateUrl = CommonHelper.GetStoreLocation() + "shoppingcart.aspx";
						hlOrdering.NavigateUrl = CommonHelper.GetStoreLocation() + "ordering.aspx";
						hlConfirm.NavigateUrl = CommonHelper.GetStoreLocation() + "checkoutconfirm.aspx";
						hlComplete.NavigateUrl = string.Empty;
					}
					break;
				case "complete":
					{
						hlCart.NavigateUrl = string.Empty;
						hlOrdering.NavigateUrl = CommonHelper.GetStoreLocation() + "ordering.aspx";
						hlConfirm.NavigateUrl = string.Empty;
						hlComplete.NavigateUrl = string.Empty;
					}
					break;
				default:
					{
						hlCart.NavigateUrl = string.Empty;
						hlOrdering.NavigateUrl = string.Empty;
						hlConfirm.NavigateUrl = string.Empty;
						hlComplete.NavigateUrl = string.Empty;
					}
					break;
			}
		}

		public string GetStatusCss(string step)
		{
			if(this.OrderProgressStep.ToLowerInvariant() == step.ToLowerInvariant())
				return "active-step";
			else
				return "inactive-step";
		}

		public string OrderProgressStep
		{
			get
			{
				object obj2 = this.ViewState["OrderProgressStep"];
				if(obj2 != null)
					return (string)obj2;
				else
					return string.Empty;
			}
			set
			{
				this.ViewState["OrderProgressStep"] = value;
			}
		}

	}
}